package com.ly.web.controller.erp;

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ly.heart.domain.CustomerEntity;
import com.ly.heart.domain.dto.CustomerDto;
import com.ly.heart.domain.dto.SaleQuotationDetailDto;
import com.ly.heart.domain.vo.SaleQuotationDetailVo;
import com.ly.heart.service.IMaterialDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.SaleQuotationEntity;
import com.ly.heart.service.ISaleQuotationService;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 销售报价单Controller
 * 
 * @author wutao
 * @date 2024-06-27
 */
@Api(value = "quotation", tags = "销售报价单")
@RestController
@RequestMapping("/heart/quotation")
public class SaleQuotationController extends BaseController {

    @Resource
    private ISaleQuotationService saleQuotationService;
    @Resource
    private IMaterialDetailService materialDetailService;

    /**
     * 查询销售报价单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:quotation:list')")
    @GetMapping("/list")
    @ApiOperation("查询销售报价单列表")
    public AjaxResult list(SaleQuotationDetailDto saleQuotationDetailDto)
    {
        IPage<SaleQuotationDetailVo> saleQuotationDetailVoIPage = materialDetailService.selectSaleQuotationDetailVoList(saleQuotationDetailDto);
        return AjaxResult.success(saleQuotationDetailVoIPage);
    }

    @PreAuthorize("@ss.hasPermi('heart:quotation:list')")
    @GetMapping("/menuList")
    @ApiOperation("新增销售订单-选单选择的报价单")
    public AjaxResult menuList(SaleQuotationDetailDto saleQuotationDetailDto)
    {
        IPage<SaleQuotationDetailVo> saleQuotationDetailVoIPage = materialDetailService.selectMenuSaleQuotationDetailVoList(saleQuotationDetailDto);
        return AjaxResult.success(saleQuotationDetailVoIPage);
    }

    /**
     * 导出销售报价单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:quotation:export')")
    @Log(title = "销售报价单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出销售报价单列表")
    public AjaxResult export(SaleQuotationEntity saleQuotation)
    {
        List<SaleQuotationEntity> list = saleQuotationService.selectSaleQuotationList(saleQuotation);
        ExcelUtil<SaleQuotationEntity> util = new ExcelUtil<SaleQuotationEntity>(SaleQuotationEntity.class);
        return util.exportExcel(list, "quotation");
    }

    /**
     * 获取销售报价单详细信息
     */
    @PreAuthorize("@ss.hasPermi('heart:quotation:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取销售报价单详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        AjaxResult ajaxResult = saleQuotationService.selectSaleQuotationById(id);
        return ajaxResult;
    }

    /**
     * 新增销售报价单
     */
//    @PreAuthorize("@ss.hasPermi('heart:quotation:add')")
//    @Log(title = "销售报价单", businessType = BusinessType.INSERT)
//    @PostMapping
//    @ApiOperation("新增销售报价单")
//    public AjaxResult add(@RequestBody SaleQuotationEntity saleQuotation)
//    {
//        return saleQuotationService.insertSaleQuotation(saleQuotation);
//    }

    @PreAuthorize("@ss.hasPermi('heart:quotation:add')")
    @Log(title = "暂存销售报价单", businessType = BusinessType.INSERT)
    @PostMapping("draft")
    @ApiOperation("暂存销售报价单")
    public AjaxResult draft(@RequestBody SaleQuotationEntity saleQuotation) {
        AjaxResult ajaxResult = saleQuotationService.draft(saleQuotation);
        return ajaxResult;
    }

    @PreAuthorize("@ss.hasPermi('heart:quotation:add')")
    @Log(title = "提交销售报价单", businessType = BusinessType.INSERT)
    @PostMapping("submit")
    @ApiOperation("提交销售报价单")
    public AjaxResult submit(@RequestBody SaleQuotationEntity saleQuotation) {
        AjaxResult ajaxResult = saleQuotationService.submit(saleQuotation);
        return ajaxResult;
    }


    /**
     * 修改销售报价单
     */
    @PreAuthorize("@ss.hasPermi('heart:quotation:edit')")
    @Log(title = "销售报价单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改销售报价单")
    public AjaxResult edit(@RequestBody SaleQuotationEntity saleQuotation)
    {

        return saleQuotationService.updateSaleQuotation(saleQuotation);
    }

    /**
     * 删除销售报价单
     */
    @PreAuthorize("@ss.hasPermi('heart:quotation:remove')")
    @Log(title = "销售报价单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除销售报价单")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return saleQuotationService.deleteSaleQuotationByIds(ids);
    }
}
